package leetcode.editor.cn;

public class _283_MoveZeroes {
    public static void main(String[] args) {
        Solution solution = new _283_MoveZeroes().new Solution();
        int[] nums = {0, 1, 0, 3, 12};
        solution.moveZeroes(nums);
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    // 类似快速排序的思想
    class Solution {
        private void swap(int[] nums, int l, int r) {
            int temp = nums[l];
            nums[l] = nums[r];
            nums[r] = temp;
        }

        public void moveZeroes(int[] nums) {
            int n = nums.length, i = 0;
            for (int j = 0; j < n; j++) {
                if (nums[j] != 0) {
                    swap(nums, i, j);
                    i++;
                }
            }
        }
    }
//leetcode submit region end(Prohibit modification and deletion)
}